package asu.util
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class TextFieldUtil
	{
		public static function setText( tf:TextField, text:String, autoSize:String="left", html:Boolean=false ):void
		{
			if( !html ) var format:TextFormat = tf.getTextFormat();
			
			if( !text ) text = '';
			
			if( autoSize )
			{
				tf.autoSize = autoSize;
			}
			
			html ? tf.htmlText = text : tf.text = text;
			
			if( autoSize )
			{
				var h:Number = tf.height;
				tf.autoSize = TextFieldAutoSize.NONE;
				tf.height = h + tf.getTextFormat().leading;
			}
			
			if( !html ) tf.setTextFormat( format );
		}
		
		public static function setHtmlText( tf:TextField, htmlText:String, autoSize:String="left" ):void
		{
			setText( tf, htmlText, autoSize, true );
			
		}
	}
}